﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace Data.MappingClasses
{
    [TableAttribute(Name = "dbo.Subdivision")]
    public partial class Subdivision : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private short _idSubdivision;

        private string _nameSubdivision;

        private EntitySet<Group> _Groups;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(ChangeAction action);
        partial void OnCreated();
        partial void OnidSubdivisionChanging(short value);
        partial void OnidSubdivisionChanged();
        partial void OnnameSubdivisionChanging(string value);
        partial void OnnameSubdivisionChanged();
        #endregion

        public Subdivision()
        {
            this._Groups = new EntitySet<Group>(AttachGroups, DetachGroups);
            OnCreated();
        }

        [ColumnAttribute(Storage = "_idSubdivision", AutoSync = AutoSync.OnInsert, DbType = "SmallInt NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public short idSubdivision
        {
            get
            {
                return this._idSubdivision;
            }
            set
            {
                if ((this._idSubdivision != value))
                {
                    this.OnidSubdivisionChanging(value);
                    this.SendPropertyChanging();
                    this._idSubdivision = value;
                    this.SendPropertyChanged("idSubdivision");
                    this.OnidSubdivisionChanged();
                }
            }
        }

        [ColumnAttribute(Storage = "_nameSubdivision", DbType = "VarChar(50) NOT NULL", CanBeNull = false)]
        public string nameSubdivision
        {
            get
            {
                return this._nameSubdivision;
            }
            set
            {
                if ((this._nameSubdivision != value))
                {
                    this.OnnameSubdivisionChanging(value);
                    this.SendPropertyChanging();
                    this._nameSubdivision = value;
                    this.SendPropertyChanged("nameSubdivision");
                    this.OnnameSubdivisionChanged();
                }
            }
        }

        [AssociationAttribute(Name = "Subdivision_Group", Storage = "_Groups", ThisKey = "idSubdivision", OtherKey = "refSubdivision")]
        public EntitySet<Group> Groups
        {
            get
            {
                return this._Groups;
            }
            set
            {
                this._Groups.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void AttachGroups(Group entity)
        {
            this.SendPropertyChanging();
            entity.Subdivision = this;
        }

        private void DetachGroups(Group entity)
        {
            this.SendPropertyChanging();
            entity.Subdivision = null;
        }
    }
}